<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>后台管理-登陆</title>
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="/plug-in/pear/css/pear.css" />
		<link rel="stylesheet" href="/plug-in/pear/admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body background="/plug-in/pear/admin/images/background.svg" style="background-size: cover;">
		<form class="layui-form" action="" lay-filter="loginData">
			<div class="layui-form-item system-login">
				<img class="logo" src="/plug-in/pear/admin/images/logo.png" />
				<div class="title">基础框架</div>
				<div class="desc">
					By Towexin
				</div>
			</div>
			<div class="layui-form-item">
				<input placeholder="账 户" name="username" lay-verify="required" hover class="layui-input" autocomplete="off" />
			</div>
			<div class="layui-form-item">
				<input type="password" placeholder="密 码" name="password" lay-verify="required" hover class="layui-input" autocomplete="off" />
			</div>
			<!--<div class="layui-form-item">-->
			<!--	<input placeholder="验证码 : "  hover  lay-verify="required" class="code layui-input layui-input-inline"  />-->
			<!--	<img src="admin/images/captcha.gif" class="codeImage" />-->
			<!--</div>-->
			<div class="layui-form-item">
				<input type="checkbox" name="rememberMe" title="记住我" lay-skin="primary" checked>
			</div>
			<div class="layui-form-item">
				<button class="pear-btn pear-btn-primary login" lay-submit="" lay-filter="login">
					登 入
				</button>
			</div>
		</form>
		<!-- 资 源 引 入 -->
		<script src="/plug-in/layui/layui.js" charset="utf-8"></script>
		<script src="/plug-in/lay-config.js" charset="utf-8"></script>
		<script>
			// 登录过期的时候，跳出ifram框架
			if (top.location != self.location) top.location = self.location;
			layui.use(["notice", "hash"], function () {
				var form = layui.form,
					$ = layui.$,
					notice = layui.notice, button = layui.button;

				notice.options = {
					positionClass:"toast-bottom-right",//弹出的位置,
					showDuration:"300",//显示的时间
					hideDuration:"500",//消失的时间
					timeOut:"1000",//停留的时间
				};


                // 登 录 提 交
				form.on('submit(login)', function (data) {
					$('button[lay-filter="login"]').attr("disabled", "").addClass("layui-btn-disabled").append(
							$("<img>").attr("src", "/plug-in/layui/css/modules/layer/default/loading-2.gif")
									.css({"width": "18px", "margin": "0 0 5px 5px"})
					)
					$(".layui-form input").attr("disabled", "disabled")
					form.val("loginData", {
						"password": layui.hash.md5(data.field.password)
					});

					$.ajax({
						url: "/user/login",
						data: {
							username: data.field.username,
							password: layui.hash.md5(data.field.password),
							rememberMe: !!data.field.rememberMe
						},
						success: function (res) {
							console.log(res)
							if (res.code === 200) {
								if (res.msg.indexOf("passwordError") !== -1) {
									notice.warning("密码错误，还有" + res.msg.split(",")[1] + "次机会", null, function () {
										//slider.reset();
										$('button[lay-filter="login"]').removeAttr("disabled").removeClass("layui-btn-disabled").find("img").remove()
										$(".layui-form input").removeAttr("disabled")
										form.val("loginData", {
											"password": ""
										});
									});
								} else if (res.msg === "noUser") {
									notice.info("用户名不存在", null, function () {
										//slider.reset();
										$('button[lay-filter="login"]').removeAttr("disabled").removeClass("layui-btn-disabled").find("img").remove()
										$(".layui-form input").removeAttr("disabled")
										form.val("loginData", {
											"username": "",
											"password": ""
										});
									});
								} else if (res.msg === "userLock") {
									notice.info("用户已被锁定，请联系管理员", null, function () {
										//slider.reset();
										$('button[lay-filter="login"]').removeAttr("disabled").removeClass("layui-btn-disabled").find("img").remove()
										$(".layui-form input").removeAttr("disabled")
										form.val("loginData", {
											"password": data.field.password
										});
									});
								} else {
									notice.success("欢迎回来", null, function () {
										window.location = "/index"
									});
								}
							}
						},
						error: function (err) {
							notice.error("请求失败", null, function () {
								//slider.reset()
								$('button[lay-filter="login"]').removeAttr("disabled").removeClass("layui-btn-disabled").find("img").remove()
							});
						}
					})
					return false;
				});
			})
		</script>
	</body>
</html>
